package cn.fancy.sdk.login;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import cn.fancy.sdk.common.utils.ResUtil;
import cn.fancy.sdk.login.view.FindPassMain;
import cn.fancy.sdk.login.view.LoginView;
import cn.fancy.sdk.login.view.RealMainCompleteView;

public class DeleteUserDialog extends Dialog {
    
    public View mainView;
    public Button cancelBt, confireBt;
    private Context mcontext;
    
    private TextView username;
    
    public DeleteUserDialog(Context context, final int which){
        super(context, ResUtil.getStyleId(context, "guild_download_dialog"));
        new DeleteUserDialog(context, which, null);
    }
    
    public DeleteUserDialog(Context context, final int which, final DeleteCallback deleteCallback) {
        super(context, ResUtil.getStyleId(context, "guild_download_dialog"));
        mcontext = context;
        
        mainView = (LayoutInflater.from(context)).inflate(
            ResUtil.getLayoutId(context, "guild_delete_sure"), null);
        mainView.setBackgroundResource(ResUtil.getDrawableId(context,
            "guild_pay_dailog_shape"));
        this.setContentView(mainView);
        
        username = (TextView) this.findViewById(ResUtil.getId(mcontext,
            "guild_delete_user"));
        
        switch (which) {
            case 0:
                username.setText(LoginView.staticdeleteusername);
                break;
            case 1:
                username.setText(FindPassMain.staticdeleteusername);
                break;
            case 3:
                username.setText(RealMainCompleteView.staticdeleteusername);
                break;
            default:
                break;
        }
        
        cancelBt = (Button) this.findViewById(ResUtil.getId(context,
            "guild_delete_cancel_btn"));
        cancelBt.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View v) {
                DeleteUserDialog.this.cancel();
            }
        });
        
        confireBt = (Button) this.findViewById(ResUtil.getId(context,
            "guild_delete_confirm_btn"));
        confireBt.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View v) {
                if (which == 0) {
                    if (deleteCallback != null) {
                        deleteCallback.onDelete();
                    }
                } else if (which == 1) {
                    if (deleteCallback != null) {
                        deleteCallback.onDelete();
                    }
                } else if (which == 3) {
                    RealMainCompleteView
                        .deleteUser(RealMainCompleteView.Viewtext);
                }
                DeleteUserDialog.this.cancel();
            }
        });
        
        setOnCancelListener(new OnCancelListener() {
            
            @Override
            public void onCancel(DialogInterface dialog) {
                LoginView.auto_cancel = true;
            }
        });
    }
    
    public interface DeleteCallback{
        void onDelete();
    }
}
